Libreries to install:

#install.packages(“tidyverse”) .- tibble using and other tools #install.packages(“sf”) .- Geospatial data of several countries #install.packages(“maps”) .- USA Regions data #install.packages(“tools”) .- Different R utilites to use in graphic titles for example #install.packages(“utils”) .- Several R utilities #install.packages(“stringr”) .- handling of text strings #install.packages(“rnaturalearth”) .- Many countries data #install.packages(“rnaturalearthdata”).- Needed to create a great map #install.packages(“ggrepel”) .- Used for labels do not overlap on the map #install.packages(“magick”) .- To generate animations with pre-built maps #install.packages(“readxl”) .- for reading excel files #install.packages(“R.utils”).- To get several functions like isZero #install.packages(“patchwork”) #install.packages(“psych”) #install.packages(“MLmetrics”) #install.packages(“DiagrammeR”) ## Calling for the nedeed libraries:

library (yaml)
library(tidyverse)
library(sf) 
library(maps)
library (tools)
library(utils)
library(stringr)
library(rnaturalearth)
library(rnaturalearthdata)
library(ggrepel)
library(transformr)
library(magick)
library(readxl)
library(lubridate)
library(gganimate)
## Enviroment variables
#List for the years related to Air Quality Data
datayears = c("2017","2018","2019","2020")

# Defining variables for directories
prename="airdata"
airfilepath="./Data/Air_Quality/"


# If png does not exist then we create it
if  (!(dir.exists("./png/")))
  {dir.create("./png/")}

pngpath="./png/"
datapath="./Data/"
popfilepath="./Data/Population/"
imgpath="/images/"
Visitspath="./Data/Hospital_Visits/"

# Defining file names variables to load the data
filename="daily_aqi_by_county_"
Visitsfile="HCUP_SummaryTrendTables_T5a.xlsx"
filepop="nst-est2020-alldata.csv"

# Defining file names variables to save the data
file_aqi_save = "Air_Quality_Indexes.Rdata"
file_visits_save = "Hosp_visits_pop_by_state.Rdata"

#Generate not_in function for different uses
`%not_in%` <- purrr::negate(`%in%`)
## Loading Data from “Dialy Air Quality Monitor”
From: https://www.hcup-us.ahrq.gov/reports/trendtables/summarytrendtables.jsp#export

Aggregate AQI USA County Data by Month per Year

Each NAAQS pollutant has a separate AQI scale, with an AQI rating of 100 corresponding to the concentration of the Federal Standard for that pollutant.
A caption

A caption

# calling function to load and group Air quality data by 2017 to 2020:
## Merging with geographical data for USA Counties, from packages(“sf”), and saving as RData:
## Now representing Air Quality on a USA geographical detailed by county:

Now saving maps as .png

Animate maps

Including animated GIF of the Air Quality cheks on a USA geographical counties

For the 2017 to 2020 years:

## Loading New Data Set, Hospital visits related to respiratory diseases:
From: https://www.hcup-us.ahrq.gov/reports/trendtables/summarytrendtables.jsp#export
This is an excel report and the different States date are in different sheets of the same excel workbook
## Including geographical USA states data to attach to the Hospital visits dataset
# Generating a map with Hospital Visists per year and month

Looping all created maps for a moving image

## Saving generated maps
## Generating an animated map of Hospital Visists

## # A tibble: 6 x 6
##   REGION DIVISION STATE NAME             POPULATION  YEAR
##   <chr>  <chr>    <int> <chr>                 <int> <dbl>
## 1 0      0            0 United States     325122128  2017
## 2 0      0            0 United States     326838199  2018
## 3 0      0            0 United States     328329953  2019
## 4 0      0            0 United States     329484123  2020
## 5 1      0            0 Northeast Region   56083383  2017
## 6 1      0            0 Northeast Region   56084543  2018